package com.farmer.controller;

import com.farmer.pojo.Information;
import com.farmer.pojo.Policy;

import com.farmer.service.PolicyService;
import com.farmer.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("policy")
@CrossOrigin
public class PolicyController {
    @Autowired
    private PolicyService policyService;


    @PostMapping("add")
    public Result add(@RequestBody Policy policy) {
        Result result = policyService.add(policy);
        return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        Result result = policyService.delete(id);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Policy policy) {
        Result result = policyService.update(policy);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = policyService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
        Result result = policyService.getAll();
        return result;
    }

    /*
     * 根据标题模糊查询*/
    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String title){
        Result result = policyService.getByTitleLike(title);
        return result;
    }

    @GetMapping("show")
    public Result show(){
        Result result = policyService.show();
        return  result;
    }
    @DeleteMapping("delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        Result result = policyService.deleteBatch(ids);
        return result;
    }
    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result=policyService.page(pageNum,pageSize);
        return result;
    }
}
